//购物车仓库
import {reqShopCartList} from '@/api';
//引入创建临时身份模块
import { userTemp } from '@/utils/temp_token'
//购物车的仓库
const state ={
    //程序运行起来的时候，仓库已经有了，用户临时身份存储到vuex中
      userTempId:userTemp(),
      //当前临时用户的购物车数据
      shopList:[],
     
}
const mutations ={
    GETSHOPCART(state,shopList){
      state.shopList = shopList;
    }
};
const actions = {
    async getShopCartData({commit}){
        let result = await reqShopCartList();
        //测试打印获取到的购物车数据
        console.log(result.data);
        if(result.code==200){
            commit("GETSHOPCART",result.data)
        }     
    }
}
const getters ={
    //简化购物车中的数据
    //当前购物车模块中的state并非大仓库中state数据【只是包含购物车state数据】
    shopCartData(state){
        return state.shopList[0]||{}
    },
    // shopList(shopList){
    //     return shopList.cartInfoList||[]
    // }
}
export default {
    state, 
    mutations,
    actions,
    getters
}
